//点击头部切换内容区
	mui('#deal_title').on('tap', 'li', function() {
		var ths = jQuery(this);
		var _type = ths.attr('data-cont');
		var dom = '.' + ths.attr('data-cont');
		/*if(!ths.hasClass('active')) {
			ths.addClass('active').siblings().removeClass('active');
			jQuery(dom).show().siblings().hide();
		}*/
		switch(_type) {
			case 'sale':
				//买卖
				mui.openWindow({
					url:'deal.html',
					id:'deal.html'
				})
				clearInterval(stockOneTimer);
				stockOneTimer = setInterval(stockOne,2000);
				break;
			case 'cancleDeal':
				//撤单
				mui.openWindow({
					url:'cancelTrade.html',
					id:'cancelTrade.html'
				})
				
				break;
			case 'holdCast':
				//持仓
				mui.openWindow({
					url:'holdStock.html',
					id:'holdStock.html'
				})
				break;
			case 'goldInOut':
				//出入金
				mui.openWindow({
					url:'goldInOut.html',
					id:'goldInOut.html'
				})
				clearInterval(stockOneTimer);
				break;
			case 'searchC':
				//查询
				console.log(_type);
				mui.openWindow({
					url:'tradeList.html',
					id:'tradeList.html'
				})
				clearInterval(stockOneTimer);
				break;
		}
	})
var priceReg=/(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/;
var _codeType = '';
var codeType;//股票类型
var priceC;//当前股票的价钱（2s刷新后会更新）
var mggs;//当前股票  手数值
var href = location.href;
var code = href.split("?code=")[1];
var stockOneTimer='';
var maxOutCharge,minInCharge,outRate,inRate,usdFund;
var tradeDeal = function(){
	return{
		stockSale:function(){
			if(code){
				stockOneInfo();	
				stockOneTimer = setInterval(stockOne,2000);
			}
			//获取持仓股票信息
			holdStock();
			setInterval(holdStock,2000);
			holdCastHead();
			pageEve(); //页面通用事件
		},
		cancel:function(){
			//获取持仓股票信息
			holdStock();
			setInterval(holdStock,2000);
			holdCastHead();
			pageEve(); //页面通用事件
			waitStock();
			cancelStock();
			clearInterval(stockOneTimer);
		},
		holdStock:function(){
			holdStock();
			setInterval(holdStock,2000);
			holdCastHead();
			pageEve(); //页面通用事件
			clearInterval(stockOneTimer);
			setInterval(holdCastHead,2000);
		},
		goldInOut:function(){
			var  username = jQuery('input[name="name"]'),
			shouji = jQuery('input[name="phone"]'),
			yinh = jQuery('input[name="creditcard"]'),
			shanfan = jQuery('input[name="IDnumber"]'),
			money = jQuery('.goldInNum'),
			Dollar;
			 username.blur(function(){
			    	var cantent = jmz.checkStr(username.val());
			    	if(cantent !== true ){
			    		mui.toast(cantent);
			    		return;
			    	}
			    });
			shouji.blur(function(){
				var cantent = jmz.checkMobile(shouji.val());
				if(cantent !==true){
					mui.toast(cantent);
			    	return;
				}
			})
			yinh.blur(function(){
				var cantent = jmz.TypeCard(yinh.val());
				if(cantent !== true){
					mui.toast(cantent);
			    	return;
				}
			})
			shanfan.blur(function(){
				var cantent = jmz.isCardID(shanfan.val());
				if(cantent !== true){
					mui.toast(cantent);
			    	return;
				}
			});
			money.blur(function(){
				var cantent = money.val();
				if(!cantent){
					mui.toast('入金金额不能为空');
					return;
				};
			});
			money.keydown(function(){
				setTimeout(function(){
					Dollar = toDecimal2(money.val()/inRate);
					jQuery('.minInNum').html("<i>"+Dollar+"</i>")
				},300)
			})
			jQuery('#credittijiao').click(function(){
				var usernamenum = username.val(),
				shoujinum = shouji.val(),
				yinhnum = yinh.val(),
				shenfannum = shanfan.val(),
				moneynum = money.val();
//				入金金额验证
				if(!moneynum){
					mui.toast('入金金额不能为空');
					return;
				};
//				名字验证
				if(!usernamenum){
					mui.toast('名字不能为空');
				    return;
				}else{
					var cantent = jmz.checkStr(usernamenum);
			    	if(cantent !== true ){
			    		mui.toast(cantent);
			    		return;
			    	};
				};
//				手机号验证
				if(!shoujinum){
					mui.toast('手机号不能为空');
				    return;
				}else{
					var cantent = jmz.checkMobile(shoujinum);
					if(cantent !==true){
						mui.toast(cantent);
				    	return;
					};
				};
//				银行卡验证
				if(!yinhnum){
					mui.toast('银行卡号不能为空');
				    return;
				}else{
					var cantent = jmz.TypeCard(yinhnum);
					if(cantent !== true){
						mui.toast(cantent);
				    	return;
					};
				};
//				身份证号验证
				if(!shenfannum){
					mui.toast('身份号不能为空');
				    return;
				}else{
					var cantent = jmz.isCardID(shenfannum);
					if(cantent !== true){
						mui.toast(cantent);
				    	return;
					};
				};
				var _data= {
					type:"0",
					fee:moneynum,
					cardNo:yinhnum,
					account:account,
					idCardNo:shenfannum,
					payType:"1",
					usdFee:Dollar
				}
				console.log(_data);
				jQuery.ajax({
					type:'post',
					url:server.paynum,
					data:_data,
					dataType:'json',
					success:function(result){
//						console.log(result.data)
						jQuery('#version').val(result.data.version);
						jQuery('#charset').val(result.data.charset);
						jQuery('#language').val(result.data.language);
						jQuery('#signType').val(result.data.signType);
						jQuery('#tranCode').val(result.data.tranCode);
						jQuery('#merchantID').val(result.data.merchantID);
						jQuery('#merOrderNum').val(result.data.merOrderNum);
						jQuery('#tranAmt').val(result.data.tranAmt);
						jQuery('#feeAmt').val(result.data.feeAmt);
						jQuery('#currencyType').val(result.data.currencyType);
						jQuery('#frontMerUrl').val(result.data.frontMerUrl);
						jQuery('#backgroundMerUrl').val(result.data.backgroundMerUrl);
						jQuery('#tranDateTime').val(result.data.tranDateTime);
						jQuery('#virCardNoIn').val(result.data.virCardNoIn);
						jQuery('#tranIP').val(result.data.tranIP);
						jQuery('#isRepeatSubmit').val(result.data.isRepeatSubmit);
						jQuery('#goodsDetail').val(result.data.goodsDetail);
						jQuery('#buyerName').val('MWEB');
						jQuery('#buyerContact').val(result.data.buyerContact);
						jQuery('#goodsName').val(result.data.goodsName)
						jQuery('#merRemark1').val(result.data.merRemark1);
						jQuery('#merRemark2').val(result.data.merRemark2);
						jQuery('#signValue').val(result.data.signValue);
						jQuery('#bankCode').val(result.data.bankCode);
						jQuery('#userType').val(result.data.userType);
						jQuery('#gopayServerTime').val(result.data.gopayServerTime);
						$('#returnfunc').submit();
					},
					error:function(result){
						mui.alert('支付失败，请重新支付','提示','确定');
					}
				})
			})
			
			
			jQuery.ajax({
				type:'post',
				url:server.stockholdCast,
				data:{
					account:account
				},
				dataType:'json',
				success:function(result){
					console.log(result);
					maxOutCharge = Number(result.data.maxOutCharge);
					minInCharge = Number(result.data.minInCharge);
					outRate =  Number(result.data.outRate);
					inRate =  Number(result.data.inRate);
					usdFund = Number(result.data.usdFund);
					jQuery('.usdCanFee').html(usdFund);
					jQuery('.minInNum i').html(minInCharge);
					goldInEve();
				},
				error:function(result){
					console.log(result);
				}
			})
			//支付方式切换事件
			jQuery('.payType').on('change',function(){
				var ths = jQuery(this);
				var _type = ths.find('option:selected').attr('value');
				switch(_type){
					case '0'||0:
						//扫码支付
						jQuery('.payCode').show();
						jQuery('.payCard').hide();
						break;
					case '1'||1:
						//银联支付
						jQuery('.payCode').hide();
						jQuery('.payCard').show();
						break;
				}
			})
			//出入金切换
			mui(".money_total ul").on('tap','li',function(event){
				var ths = jQuery(this);
				var type = ths.attr('data-gold');
				ths.addClass('active').siblings().removeClass('active');
				switch(type){
					case 'in':
						jQuery("#ig1").attr("src", "images/img.png"); 
						jQuery("#ig2").attr("src", "images/img1.png");
						jQuery('.goldIncont').show();
						jQuery('.goldOutcont').hide();
						goldInEve();
						break;
					case 'out':
						jQuery("#ig1").attr("src", "images/img1.png"); 
						jQuery("#ig2").attr("src", "images/img.png");
						jQuery('.goldIncont').hide();
						jQuery('.goldOutcont').show();
						goldOutEve();
						break;
				}
			});
		},
		searchTabPage:function(){
			mui('.searchC').on('tap','#title_trade',function(){
				mui.openWindow({
					url: 'dayTrade.html',
					id: 'dayTrade.html'
				});
			})
			mui('.searchC').on('tap','#title_commissio',function(){
				mui.openWindow({
					url: 'dayCommissio.html',
					id: 'dayCommissio.html'
				});
			})
			mui('.searchC').on('tap','#history_trade',function(){
				mui.openWindow({
					url: 'historyTrad.html',
					id: 'historyTrad.html'
				});
			})
			mui('.searchC').on('tap','#history_commissio',function(){
				mui.openWindow({
					url: 'historyCommissio.html',
					id: 'historyCommissio.html'
				});
			})
			mui('.searchC').on('tap','#deposit',function(){
				mui.openWindow({
					url: 'deposit.html',
					id: 'deposit.html'
				});
			})
			mui('.searchC').on('tap','#gold',function(){
				mui.openWindow({
					url: 'gold.html',
					id: 'gold.html'
				});
			})
			mui('.searchC').on('tap','#goldDetail',function(){
				mui.openWindow({
					url: 'money.html',
					id: 'money.html'
				});
			})
		}
	}
}
/*
 * 1.进入页面 从URL获取code值  如果存在code值 则直接请求code值对应的股票信息进行填充  请求之后2s刷新一次
 * 2.如果code值不存在  则不进行数据获取  
 * 	3.进入页面直接请求买/卖页面底部持仓股票的列表数据holdStock（数据请求之后直接template到day_list and day_lists 内容承载区中）也是2s 刷新一次
 * 4 点击头部列表进行不同div切换之后调用当前div对应的逻辑处理函数
 * */
/*
 * 买/卖部分逻辑处理（code值存在）
 * 1、获取code值并请求code值对应的股票数据进行信息填充  注意：保存当前最新价 每次刷新的时候更新最新价格
 * p1 股票名称 p2  涨跌值  p3 涨跌幅度  hi 涨停价  lo跌停价 mony 收盘价  numIn手数 stoke_num  股票代码  
 * 2、市价 限价切换 对价格的加减有变化   市价的话不可以对价格进行加减，使用当前最新的价格  限价的话可以对当前的价格进行变化
 * */
	//入金 逻辑处理
	function goldInEve(){
		mui('.payCode').on('tap','.paySure',function(){
			var _inprice = Number(jQuery('.goldInNum').val());
			if(_inprice==''){
				mui.toast('请输入入金金额');return false;
			}else if(!priceReg.test(_inprice)){
				mui.toast('请输入正确的入金金额');return false;
			}else if(_inprice<minInCharge){
				mui.toast('入金金额不得小于最小入金金额');return false;
			}else{
				var _data = {
					account:account,
					type:0,
					fee:_inprice,
					usdFee:(_inprice/inRate).toFixed(2)
				}
				console.log(_data);
				goldApply(_data);
			}
		})
	}
	//出金 逻辑处理
	function goldOutEve(){
		var status;
		jQuery.ajax({
			type:'post',
			url:server.stockMdetail,
			data:{
				account:account
			},
			dataType:'json',
			success:function(result){
				console.log(result);
				status = result.data.status;//0：正常 1：待审核 2：未开户 -1：删除 -2拒绝
				if(status==0){
					dataHandler(result.data);
				}else if(status==1){
					mui.confirm('您的申请正在审核，暂不能出金','出金提示',['确定','取消'],function(e){},['div'])
				}else{
					mui.confirm('您还未实名认证，暂不能出金','出金提示',['确定','取消'],function(e){
						 if (e.index == 0) {
		                    mui.openWindow({
								url:"openAccount.html",
								id:'openAccount.html'
							})
	                    }else{
	                    	
	                    }
					},['div'])
				}
			},
			error:function(result){
				console.log(result);
			}
		});
		
		function dataHandler(data){
			jQuery('.cardBank').html(data.stockUserInfo.cardType);
			jQuery('.cardNum').html(data.stockUserInfo.cardNo);
			jQuery('.canFee').html(data.stockUserInfo.usableFund)
		}
		mui('.goldOutcont').on('tap','.paySure',function(){
			var _price = Number(jQuery('.outFee').val());
			if(_price==''){
				mui.toast('请输入出金金额');return false;
			}else if(!priceReg.test(_price)){
				mui.toast('请输入正确的出金金额');return false;
			}else if(_price>maxOutCharge){
				mui.toast('出金金额不能大于最大出金额');return false;
			}else{
				var _data = {
					account:account,
					type:1,
					cardType:jQuery('.cardBank').html(),
					cardNo:jQuery('.cardNum').html(),
					fee:(_price*outRate).toFixed(2),
					usdFee:_price
				}
				console.log(_data);
				goldApply(_data);
			}
		})
	}
	//出金入金申请
	function goldApply(_data){
		jQuery.ajax({
			type:'post',
			url:server.stockApply,
			data:_data,
			dataType:'json',
			beforeSend:function(){
				maskShowEvent();
			},
			success:function(result){
				maskHideEvent();
				mui.toast(result.msg);
				console.log(result);
			},
			error:function(result){
				console.log(result);
				maskHideEvent();
				mui.toast('操作失败，请重试');
			}
		})
	}

	function stockOneInfo() {
		jQuery.ajax({
			type: 'post',
			url: server.stockOne,
			data: {
				stockCode: code,
				account: account
			},
			dataType: 'json',
			success: function(result) {
				if(result.code == 0) {
					//基本数据填充  p1 股票名称 p2  涨跌值  p3 涨跌幅度  hi 涨停价  lo跌停价 mony 收盘价  numIn手数 stoke_num  股票代码  
					jQuery('#p1').html(result.data[0].name);
					jQuery('#p2').html(result.data[0].change);
					jQuery('#p3').html(result.data[0].changeRate+'%');
					jQuery('#mony').val(result.data[0].price);
					jQuery('#stoke_num').val(result.data[0].code);
					//股票类型判断
					codeType = result.data[0].type;
					var cprice = Number(result.data[0].price);
					priceC = Number(result.data[0].price);
					var cNum  = Number(result.data[0].mggs);
					if(codeType=='2'){
						//港股
						jQuery('.codeType').html('(hkd)');
						jQuery('.kuNum').html((cprice*cNum).toFixed(3));
					}else{//美股
						jQuery('.codeType').html('(usd)');
						jQuery('.kuNum').html((cprice*cNum).toFixed(3));
					}
					//计算涨停价  跌停价
					var openPrice = Number(result.data[0].openPrice);
					var closePrice = Number(result.data[0].closePrice);
					var rate = 0.1;
					var highPrice = (closePrice * (1+ rate)).toFixed(3);
					var lowPrice = (closePrice * (1 - rate)).toFixed(3);
					jQuery('#hi').html(highPrice);
					jQuery('#lo').html(lowPrice);
					//手数信息
					jQuery('.priceMin').html(result.data[0].jggd);
					var nm = jQuery('.numMin').html();
					var ni = jQuery('.numInner').val();
					if(nm!=''){
						jQuery('.numMin').html(result.data[0].mggs);
						jQuery('.numInner').val(result.data[0].mggs);
					}
					mggs = Number(result.data[0].mggs);
					personInfo();//请求个人资金信息
				}
			},
			error: function(xhr, type, errorThrown) {
				//异常处理；
				console.log(type);
			}
		})
	}

	function personInfo(){
		jQuery.ajax({
			type:'post',
			url:server.stockholdCast,
			data:{
				account:account
			},
			dataType:'json',
			success:function(result){
				console.log(result);
				var fee;
				if(codeType==2){
					fee =Number(result.data.hkFund).toFixed(2);
				}else{
					fee =Number(result.data.usdFund).toFixed(2);
				}
				jQuery('.personFee').html(fee);
			},
			error:function(result){
				console.log(result);
			}
		})
	}

	function stockOne() {
		jQuery.ajax({
			type: 'post',
			url: server.stockOne,
			data: {
				stockCode: code,
				account: account
			},
			dataType: 'json',
			success: function(result) {
				if(result.code == 0) {
					console.log('stockOne');
					//基本数据填充  p1 股票名称 p2  涨跌值  p3 涨跌幅度  hi 涨停价  lo跌停价 mony 收盘价  numIn手数 stoke_num  股票代码  
					jQuery('#p1').html(result.data[0].name);
					jQuery('#p2').html(result.data[0].change);
					jQuery('#p3').html(result.data[0].changeRate+'%');
					jQuery('#mony').val(result.data[0].price);
					jQuery('#stoke_num').val(result.data[0].code);
					//股票类型判断
					codeType = result.data[0].type;
					var cprice = Number(result.data[0].price);
					priceC = Number(result.data[0].price);
					var cNum  = Number(result.data[0].mggs);
					//计算涨停价  跌停价
					var openPrice = Number(result.data[0].openPrice);
					var closePrice = Number(result.data[0].closePrice);
					var rate = 0.1;
					var highPrice = (closePrice * (1+ rate)).toFixed(3);
					var lowPrice = (closePrice * (1 - rate)).toFixed(3);
					jQuery('#hi').html(highPrice);
					jQuery('#lo').html(lowPrice);
					//手数信息
					jQuery('.priceMin').html(result.data[0].jggd);
					mggs = Number(result.data[0].mggs);
				}
			},
			error: function(xhr, type, errorThrown) {
				//异常处理；
				console.log(type);
			}
		})
	}

	function pageEve() {
		//点击切换市价  限价
		jQuery('.priceType').on('change', function() {
			clearInterval(stockOneTimer);
			jQuery('#mony').val(priceC);
			var hands = (mggs*priceC).toFixed(3);
			jQuery('.kuNum').html(hands);
			jQuery('#numIn').val(mggs);
			//mggs
			var _type = jQuery(this).find('option:selected').val();
			switch(_type) {
				case '0':
					//市价
					jQuery('#bt2 .delBtnS,#bt2 .addBtnS').hide();
					break;
				case '1':
					//限价
					jQuery('#bt2 .delBtnS,#bt2 .addBtnS').show();
					break;
			}
			stockOneTimer = setInterval(stockOne,2000)
		})
		
		mui("#cocle").on('tap', 'ul', function() {
			var ths = jQuery(this);
			var i = jQuery(this).index();
			var val = ths.find("li:nth-child(2)").text(); //注意：这里的下标从一开始，或者使用:first-child  
			document.getElementById("stoke_num").value = val;
			document.getElementById("scroll").style.display = 'none';
		});
		var domInput = document.getElementById("stoke_num");
		if(domInput){
			document.getElementById("stoke_num").addEventListener('input', function() {
				clearInterval(stockOneTimer);
				var arr = [];
				var val = this.value;
				var val = jQuery(this).val();
				jQuery("#searchRes").empty();
				if(val == '') {
					jQuery("#searchRes").empty();
				} else {
					jQuery('#scroll').show();
					jQuery('body').css('overflow', 'hidden');
					//document.getElementById("scroll").style.display='block';
					for(var i = 0, resArr = []; i < list.length; i++) {
						if(list[i].code.indexOf(val) != -1) {
							//console.log('包含--'+list[i].code)
							var src = '';
							if(list[i].type == 'HK') {
								src = 'images/HK_20x15_@3x.png';
							} else {
								src = 'images/US_40_29.png';
							}
							jQuery("#searchRes").append("<ul class='mui-row'><li class='mui-col-sm-2 mui-col-xs-2'><img src='" + src + "' alt='' class='mui-pull-left'></li><li class='mui-col-sm-4 mui-col-xs-4'><span>" + list[i].code + "</span></li><li style='text-align: right;' class='mui-col-sm-6 mui-col-xs-6'><span style='margin-right:10px;'>" + list[i].name + "</span></li></ul>");
						}
					}
					mui('.mui-scroll-wrapper').scroll({
						scrollY: true, //是否竖向滚动
						scrollX: false, //是否横向滚动
						startX: 0, //初始化时滚动至x
						startY: 0, //初始化时滚动至y
						indicators: true, //是否显示滚动条
						deceleration: 0.0006, //阻尼系数,系数越小滑动越灵敏
						bounce: true //是否启用回弹
					});
				}
			});
		}
		//单支股票信息获取
		mui("#searchRes").on('tap', 'ul', function() {
			var i = jQuery(this).index();
			// alert(i);
			var val = jQuery(this).find("li:nth-child(2)").text(); //注意：这里的下标从一开始，或者使用:first-child  
			document.getElementById("stoke_num").value = val;
			jQuery('body').css('overflow', 'scroll');
			document.getElementById("scroll").style.display = 'none';
			code = val;
			stockOneInfo();
			stockOneTimer = setInterval(stockOne,2000);
		});
		//区域滚动
		mui('.mui-scroll-wrapper').scroll({
			scrollY: true, //是否竖向滚动
			scrollX: false, //是否横向滚动
			startX: 0, //初始化时滚动至x
			startY: 0, //初始化时滚动至y
			indicators: false, //是否显示滚动条
			deceleration: 0.0005, //阻尼系数,系数越小滑动越灵敏
			bounce: true //是否启用回弹
		});
		
		//点击购买
		mui('.select_total').on('tap', '#buy,#sale', function() {
			var ths = jQuery(this);
			ths.addClass('tradeAct');
			ths.siblings().removeClass('tradeAct');
			var title = document.getElementById('p1').innerHTML;
			var price = jQuery('#mony').val();
			var code = document.getElementById("stoke_num").value;
			var name = document.getElementById("p3").innerHTML;
			var num = document.getElementById("numIn").value;
			//var type = document.getElementById("in").value;
			if(!title || !price || !code || !name || !num) {
				mui.toast('请先选择股票');
				return false;
			} else {
				document.getElementById("title").innerHTML = title;
				document.getElementById("title4").innerHTML = code;
				document.getElementById("title1").innerHTML = price;
				document.getElementById("title2").innerHTML = num;
				var _type = jQuery('.select_total .tradeAct').attr('data-type');
				var _str = _type==0 ? '买入':'卖出';
				document.getElementById("title3").innerHTML = _str;
				jQuery("#tost").show();
				mui('#tost').on('tap', '#btn1', function() {
					var code = document.getElementById("stoke_num").value;
					var pic = jQuery('#mony').val();
					var num = document.getElementById("numIn").value;
					//var market=document.getElementById("price").innerHTML;
					var _billType = jQuery('.priceType option:selected').val();
					var _type = jQuery('.select_total .tradeAct').attr('data-type');
					var _data = {
						account: account,
						tradingType: _type,
						entrustCount: num,
						price: pic,
						stockCode: code,
						currency: codeType == 2 ? 1 : 2,
						billType: _billType
					};
					//console.log(_data);
					dealEve(_data);
				})
				mui('#tost').on('tap', '#btn2', function() {
					jQuery("#tost").hide();
				})
			}
		});
		//点击信息确定按钮之后 进行购买
		function dealEve(_data) {
			jQuery("#tost").hide();
			jQuery.ajax({
				type: 'post',
				url: server.stockABill,
				data: _data,
				dataType:'json',
				beforeSend:function(){
					maskShowEvent();
				},
				success: function(result) {
					maskHideEvent();
					mui.toast(result.msg);
				},
				error: function(result) {
					maskHideEvent();
					console.log(result);
				}
			})
		}

		//点击数量减
		mui('#numAddDel').on('tap', '.delBtnS', function() {
			var minNum = Number(jQuery('.numMin').html());
			var numcur = Number(jQuery('#numAddDel .numInner').val());
			var pricehands = Number(jQuery('#mony').val());
			if(numcur > 0) {
				var numres = (numcur - minNum) > 0 ? (numcur - minNum) : 0;
				jQuery('#numAddDel .numInner').val(numres);
				jQuery('.kuNum').html((numres*pricehands).toFixed(3))
			}
			
		})
		//点击数量加
		mui('#numAddDel').on('tap', '.addBtnS', function() {
			var minNum = Number(jQuery('.numMin').html());
			var numcur = Number(jQuery('#numAddDel .numInner').val());
			var numres = (numcur + minNum);
			var pricehands = Number(jQuery('#mony').val());
			jQuery('#numAddDel .numInner').val(numres);
			jQuery('.kuNum').html((numres*pricehands).toFixed(3))
		})
		//点击价格减
		mui('#bt2').on('tap', '.delBtnS', function() {
			clearInterval(stockOneTimer);
			var minNum = Number(jQuery('.priceMin').html());
			var numcur = Number(jQuery('.priceInner').val());
			var numhands = Number(jQuery('#numIn').val());
			if(numcur > 0) {
				var numres = (numcur - minNum) > 0 ? (numcur - minNum).toFixed(3) : 0;
				jQuery('#bt2 #mony').val(numres);
				jQuery('.kuNum').html((numres*numhands).toFixed(3))
			}
		})
		//点击价格加
		mui('#bt2').on('tap', '.addBtnS', function() {
			clearInterval(stockOneTimer);
			var minNum = Number(jQuery('.priceMin').html());
			var numcur = Number(jQuery('.priceInner').val());
			var numres = (numcur + minNum).toFixed(3);
			var numhands = Number(jQuery('#numIn').val());
			jQuery('#bt2 #mony').val(numres);
			jQuery('.kuNum').html((numres*numhands).toFixed(3))
		})

	}

	function holdStock() {
		var _data = {
			account: account
		};
		jQuery.ajax({
			type: 'post',
			url: server.stockCount,
			data: _data,
			dataType: 'json',
			success: function(result) {
				console.log(result);
				if(result.data.length > 0) {
					var listDom = document.getElementById('day_list');
					var listDoms = document.getElementById('day_lists');
					if(listDom){
						jo.reTpl(jQuery('#day_temp'), {
							data: result.data
						}, jQuery('#day_list'));
					}
					if(listDoms){
						jo.reTpl(jQuery('#day_temps'), {
							data: result.data
						}, jQuery('#day_lists'));
					}
					holdCast();
				}
			},
			error: function(result) {
				console.log(result);
			}
		})
	}

	function holdCast() {
		mui('#day_lists').on('tap', 'ul', function() {
			var ths = jQuery(this);
			var _name = ths.attr('data-name');
			var _code = ths.attr('data-code');
			var _count = ths.attr('data-count');
			var _price = ths.attr('data-price');
			var _cur = ths.attr('data-cur');
			jQuery('#tost .pcName').html(_name);
			jQuery('#tost .pcCode').html(_code);
			jQuery('#tost .pcPrice').html(_price);
			jQuery('#tost .pcNumber').html(_count);
			jQuery('#tost').show();
			mui('#tost').on('tap', '#btn1', function() {
				var _data = {
						account: account,
						tradingType: 1,
						entrustCount: _count,
						price: _price,
						stockCode: _code,
						currency: _cur,
						billType: 0
					};
					stocktrade(_data);
			})
			mui('#tost').on('tap', '#btn2', function() {
				jQuery("#tost").hide();
			})
		})
	}

	function stocktrade(_data) {
		jQuery.ajax({
			type: 'post',
			url: server.stockABill,
			data: _data,
			success: function(result) {
				mui.toast(result.msg);
				jQuery("#tost").hide();
			},
			error: function(result) {
				console.log(result);
				mui.toast('交易失败，请重试');
				jQuery("#tost").hide();
			}
		})
	}

	function holdCastHead() {
		var _data = {
			account: account
		};
		jQuery.ajax({
			type: 'post',
			url: server.stockMdetail,
			data: _data,
			dataType: 'json',
			success: function(result) {
				console.log(result);
				if(result.data) {
					var domHead = document.getElementById('hold_head');
					if(domHead){
						jo.reTpl(jQuery('#hold_temp'), {
							data: result.data
						}, jQuery('#hold_head'));
					}
				}
			},
			error: function(result) {
				console.log(result);
			}
		})
	}

	function waitStock() {
		var _data = {
			account: account,
			billStatus: 2
		}
		jQuery.ajax({
			type: 'post',
			url: server.stockDay,
			data: _data,
			success: function(result) {
				console.log(result);
				if(result.code == 0) {
					if(result.data.length > 0) {
						jo.reTpl(jQuery('#temp_wait'), {
							data: result.data
						}, jQuery('#cocle'));
						cancelStock();
					}
				}
				//jQuery("#tost").hide();
			},
			error: function(result) {
				console.log(result);
			}
		})
	}

	function cancelStock() {
		mui('#cocle').on('tap', 'ul', function() {
			var ths = jQuery(this);
			var _id = ths.attr('data-id');
			var _data = {
				account: account,
				id: _id
			};
			jQuery.ajax({
				type: 'post',
				url: server.stockBill,
				data: _data,
				dataType: 'json',
				success: function(result) {
					if(result.code == 0) {
						mui.toast(result.msg);
						waitStock();
					} else {
						mui.toast(result.msg);
					}
				},
				error: function(result) {
					mui.toast('撤单失败，请重试');
				}
			})
		})
	}
